const _ = 'flow',
  d = 'block',
  v = 'quoted';
function E(
  s,
  o,
  f = 'flow',
  {
    indentAtStart: w,
    lineWidth: u = 80,
    minContentWidth: b = 20,
    onFold: F,
    onOverflow: O,
  } = {},
) {
  if (!u || u < 0) return s;
  const h = Math.max(1 + b, 1 + u - o.length);
  if (s.length <= h) return s;
  const r = [],
    L = {};
  let a = u - o.length;
  typeof w == 'number' && (w > u - Math.max(2, b) ? r.push(0) : (a = u - w));
  let i,
    n,
    g = !1,
    e = -1,
    $ = -1,
    k = -1;
  f === d && ((e = M(s, e)), e !== -1 && (a = e + h));
  for (let c; (c = s[(e += 1)]); ) {
    if (f === v && c === '\\') {
      switch ((($ = e), s[e + 1])) {
        case 'x':
          e += 3;
          break;
        case 'u':
          e += 5;
          break;
        case 'U':
          e += 9;
          break;
        default:
          e += 1;
      }
      k = e;
    }
    if (
      c ===
      `
`
    )
      f === d && (e = M(s, e)), (a = e + h), (i = void 0);
    else {
      if (
        c === ' ' &&
        n &&
        n !== ' ' &&
        n !==
          `
` &&
        n !== '	'
      ) {
        const l = s[e + 1];
        l &&
          l !== ' ' &&
          l !==
            `
` &&
          l !== '	' &&
          (i = e);
      }
      if (e >= a)
        if (i) r.push(i), (a = i + h), (i = void 0);
        else if (f === v) {
          for (; n === ' ' || n === '	'; ) (n = c), (c = s[(e += 1)]), (g = !0);
          const l = e > k + 1 ? e - 2 : $ - 1;
          if (L[l]) return s;
          r.push(l), (L[l] = !0), (a = l + h), (i = void 0);
        } else g = !0;
    }
    n = c;
  }
  if ((g && O && O(), r.length === 0)) return s;
  F && F();
  let p = s.slice(0, r[0]);
  for (let c = 0; c < r.length; ++c) {
    const l = r[c],
      D = r[c + 1] || s.length;
    l === 0
      ? (p = `
${o}${s.slice(0, D)}`)
      : (f === v && L[l] && (p += `${s[l]}\\`),
        (p += `
${o}${s.slice(l + 1, D)}`));
  }
  return p;
}
function M(s, o) {
  let f = s[o + 1];
  for (; f === ' ' || f === '	'; ) {
    do f = s[(o += 1)];
    while (
      f &&
      f !==
        `
`
    );
    f = s[o + 1];
  }
  return o;
}
export {
  d as FOLD_BLOCK,
  _ as FOLD_FLOW,
  v as FOLD_QUOTED,
  E as foldFlowLines,
};
